home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / callfkt.lha / callfunction.adoc < prev    next >
Encoding:
Text File  |  1995-01-09  |  3.5 KB  |  84 lines

  1.     NAME
  2.         CallFunction - call a library function via base/offset
  3.  
  4.     SYNOPSIS
  5.         #include <exec/types.h>
  6.         #include <exec/libraries.h>
  7.  
  8.         result = CallFunction(base, offset, d0, d1, d2, d3, d4,
  9.                               d5, d6, d7, a0, a1, a2, a3, a4);
  10.  
  11.         LONG CallFunction(struct Library *, LONG, LONG, LONG,
  12.                           LONG, LONG, LONG, LONG, LONG, LONG,
  13.                           APTR, APTR, APTR, APTR, APTR);
  14.  
  15.     FUNCTION
  16.         CallFunction allows you to call almost any library function via
  17.         its LVO (Library Vector Offset).
  18.         Library functions that take arguments in A5 or on the stack cannot
  19.         be called by CallFunction (i.e. SuperVisor(), #?LockLayerRom()).
  20.  
  21.     INPUTS
  22.         base        Pointer to the library base, as returned from OpenLibrary()
  23.         offset      The (NEGATIVE!) offset from the base for calling the desired
  24.                     function.  This value can usually be taken from:
  25.                         1) FD file of the library, the negative bias
  26.                         2) Assembler header file, usually prefixed by _LVO
  27.                         3) SAS/C or DICE "#pragma libcall" instruction
  28.         d0 ... d7   Values to be passed to the library function in registers
  29.                     D0 to D7.
  30.         a0 ... a4   Values to be passed to the library function in registers
  31.                     A0 to A4.
  32.  
  33.     RESULT
  34.         result      Value returned as result by the called library function.
  35.                     This is only valid if the library function actually returns
  36.                     a result.  CallFunction actually returns the registers
  37.                     D0, D1, A0 and A1 from the library function.  Usually only D0
  38.                     contains the result and the other three are trashed, unless
  39.                     the Autodocs of the library function states otherwise.
  40.  
  41.     EXAMPLE
  42.         #include <exec/types.h>
  43.         #include <exec/libraries.h>
  44.         #include <intuition/intuition.h>
  45.         #include <clib/exec_protos.h>
  46.  
  47.         extern __stkargs LONG CallFunction(APTR *base, LONG offset,
  48.                                 LONG d0, LONG d1, LONG d2, LONG d3,
  49.                                 LONG d4, LONG d5, LONG d6, LONG d7,
  50.                                 APTR a0, APTR a1, APTR a2, APTR a3,
  51.                                 APTR a4);
  52.  
  53.  
  54.         main()
  55.         {
  56.             LONG rc;
  57.             struct Library *demoBase;
  58.             struct EasyStruct demoES = {
  59.                 sizeof (struct EasyStruct),
  60.                 0,
  61.                 "CallFunction Demo",
  62.                 "DisplayBeep() and EasyRequestArgs() called by CallFunction()",
  63.                 "Great! Do it again!|Oh no! Stop it!",
  64.             };
  65.  
  66.             if( demoBase = OpenLibrary("intuition.library", 37) ) {
  67.                 do {
  68.                     CallFunction( demoBase, -0x60,          /* DisplayBeep */
  69.                         0, 0, 0, 0, 0, 0, 0, 0,             /* dummy values for D0-D7 */
  70.                         NULL, 0, 0, 0, 0);                  /* dummy values for A1-A4 */
  71.                     rc = CallFunction( demoBase, -0x24c,    /* EasyRequestArgs */
  72.                         0, 0, 0, 0, 0, 0, 0, 0,             /* dummy values for D0-D7 */
  73.                         NULL, (APTR)&demoES, NULL, NULL, 0);/* dummy value for A4 */
  74.                 }
  75.                 while( rc );
  76.                 CloseLibrary(demoBase);
  77.             }
  78.             return 0;
  79.         }
  80.  
  81.     SEE ALSO
  82.         exec.library/OpenLibrary, exec/library/CloseLibrary
  83.  
  84.